package ik.xcj.hostpital.manage.controller;

import com.cloopen.rest.sdk.BodyType;
import com.cloopen.rest.sdk.CCPRestSmsSDK;
import ik.xcj.hostpital.manage.security.YzmUtil;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Set;

@RestController
public class SMSController {
    @Autowired
    RedisTemplate redisTemplate;

    @Autowired
    YzmUtil yzmUtil;

    @GetMapping("/send")
    public String sendCode() {
        //生产环境请求地址：app.cloopen.com
        String serverIp = "app.cloopen.com";
        //请求端口
        String serverPort = "8883";
        //共有7处地方需要修改
        String accountSId = "2c948876853e6a16018543268af70050";
        String accountToken = "13abd1dd6f954fc3a544cbc73a690146";
        String appId = "2c948876853e6a16018543268bfc0057";


        String yzm = yzmUtil.Yzm();

        CCPRestSmsSDK sdk = new CCPRestSmsSDK();
        sdk.init(serverIp, serverPort);
        sdk.setAccount(accountSId, accountToken);
        sdk.setAppId(appId);
        sdk.setBodyType(BodyType.Type_JSON);
//        修改接收短信的手机号，手机号要在后台添加进去
        String to = "17635315171";
        String templateId = "1";
        String[] datas = {yzm, "3"};
        String subAppend = "1234000";
        String reqId = "slldls";

        HashMap<String, Object> result = sdk.sendTemplateSMS(to, templateId, datas, subAppend, reqId);
        if ("000000".equals(result.get("statusCode"))) {

            //正常返回输出data包体信息（map）
            HashMap<String, Object> data = (HashMap<String, Object>) result.get("data");
            Set<String> keySet = data.keySet();
            for (String key : keySet) {
                Object object = data.get(key);
                System.out.println(key + " = " + object);
            }
        } else {
            //异常返回输出错误码和错误信息
            System.out.println("错误码=" + result.get("statusCode") +" 错误信息= "+result.get("statusMsg"));
        }
        return "发送成功";
        }


}





